package com.financing.service.app;
import java.util.Arrays;
import java.util.Map;

import com.financing.common.CONST;
import com.financing.components.push.AppPushUtil;
import com.financing.model.app.AppPush;
import com.financing.model.user.User;
import com.financing.service.BaseService;
import com.financing.util.Str;
import com.jfinal.plugin.activerecord.Page;

public class AppPushService extends BaseService<User>{
	/**
	 * 分页信息
	 * @return
	 */
	public Page<AppPush> list(int page, int size, Map<String, String> map) {
		return AppPush.me.paginate(page, size, buildSql("app_push",Arrays.asList("name"),map));
	}
	
	public static void send(String title, String contents, String type) {
		if(Str.eq("iOS", type) || Str.eq("all", type)){
			AppPushUtil AppPush = new AppPushUtil(CONST.iosPushAppkey,CONST.iosPushMasterSecret);
			try {
				AppPush.sendIOSBroadcast(title,contents);
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
		if(Str.eq("android", type) || Str.eq("all", type)){
			AppPushUtil AppPush = new AppPushUtil(CONST.androidPushAppkey,CONST.androidPushMasterSecret);
			try {
				AppPush.sendAndroidBroadcast(title,contents);
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}
}
